package com.doubi.controller.work;

import com.doubi.common.aspectj.annotation.SysLog;
import com.doubi.model.sys.*;
import com.doubi.service.AdverService;
import com.doubi.utils.DataUtil;
import com.doubi.vo.AppModel;
import com.doubi.vo.PageVo;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("adver")
public class AdverController {
    @Autowired
    private AdverService adverService;

    @RequiresPermissions("adver:view")
    @GetMapping("view")
    public String view(){
        return "web/adver/view";
    }

    @RequiresPermissions("adver:page")
    @PostMapping("page")
    @ResponseBody
    public PageVo<TAdver> getPage(PageVo<TAdver> page, TAdver adver){
        return adverService.getPage(page,adver);
    }

    @SysLog(title = "删除广告信息")
    @RequiresPermissions("adver:del")
    @PostMapping("del")
    @ResponseBody
    public AppModel delBean(String oid){
        return adverService.delBean(oid);
    }


    @RequiresPermissions("adver:edit")
    @GetMapping("edit")
    public String edit(TAdver adver, Model model) {
        if (DataUtil.isNotEmpty(adver.getOid())) {
            adver = adverService.getById(adver.getOid());
        }
        model.addAttribute("bean", adver);
        return "web/adver/edit";
    }


    @SysLog(title = "新增，更改活动信息")
    @RequiresPermissions("adver:saveOrUpdateBean")
    @PostMapping("saveOrUpdateBean")
    @ResponseBody
    public AppModel saveOrUpdateBean(TAdver TAdver){
        return adverService.saveOrUpdateBean(TAdver);
    }

    /**
     * 功能说明：功能说明：广告状态更新 接口
     * @author  MrDoubi 2019-01-10 15:14:33
     * @param oid bean
     * @return model
     */
    @SysLog(title = "广告状态更新")
    @RequiresPermissions("adver:updateStatus")
    @PostMapping("updateStatus")
    @ResponseBody
    public AppModel updateStatus(String oid){
        return adverService.updateStatus(oid);
    }
}
